package com.rimi.service.impl;

import com.mysql.cj.result.Row;
import com.rimi.bean.CompanyInfoBean;
import com.rimi.commons.CommonResult;
import com.rimi.commons.ResultStatus;
import com.rimi.mapper.CompanyMapper;
import com.rimi.model.dto.CompanyInfoDto;
import com.rimi.service.CompanyService;
import com.rimi.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 罗晨
 * @version V1.0
 * @Description: 用一句话描述该文件做什么
 * @date 2021 2021/7/6 11:46
 */
@Slf4j
@Service
public class CompanyServiceImpl implements CompanyService {



    @Autowired
    CompanyMapper companyMapper;

    @Autowired
    UserService userService;

    @Override
    public CommonResult addCompany(CompanyInfoBean companyInfoBean) {
        int row=companyMapper.addCompany(companyInfoBean);
        return row==1?CommonResult.onSuccess(null):CommonResult.onFailed(ResultStatus.CADD_FAILED);
    }

    @Override
    public CompanyInfoBean queryCompanyByUserId(CompanyInfoBean companyInfoBean) {

        return companyMapper.queryCompanyByUserId(companyInfoBean);
    }

    @Transactional
    @Override
    public CommonResult updateCompanyInfoById(Integer id, CompanyInfoBean companyInfoBean) {

        int row=companyMapper.updateCompanyInfoById(id,companyInfoBean);
        if (row==1){
            System.out.println(id);
            userService.updateUserById(id,companyInfoBean.getUserPhoneNumber());
        }
        return row==1? CommonResult.onSuccess(null):CommonResult.onFailed(ResultStatus.UPDATE_FAILED);
    }
}
